# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libslirp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.7.0
pkgrel=1
pkgdesc="General purpose TCP-IP emulator (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://gitlab.freedesktop.org/slirp/libslirp"
license=('BSD' 'MIT')
depends=("${MINGW_PACKAGE_PREFIX}-glib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://gitlab.freedesktop.org/slirp/${_realname}/-/archive/v${pkgver}/${_realname}-v${pkgver}.tar.bz2")
sha256sums=('358ce8b6ea59ec9deac937cc754f0115b992839e7b0cddf30ffb8f77dc21da82')

prepare() {
  cd "${srcdir}"/${_realname}-v${pkgver}

}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Ddefault_library=both \
    "../${_realname}-v${pkgver}"

  ${MINGW_PREFIX}/bin/meson compile
}

package() {
  cd build-${MINGW_CHOST}
  ${MINGW_PREFIX}/bin/meson install --destdir="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-v${pkgver}/COPYRIGHT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT"
}
